package com.stylefeng.guns.rest.common;

/**
 * 通用的成功的响应
 * Created by xiongyikai on 2017/12/16.
 */
public class CommonResponse<T> {

    private static final int CODE_SUCCESS = 101;

    private int code;

    private String message;

    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> CommonResponse ok(T data){
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(101);
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static <T> CommonResponse ok(String message , T data){
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(101);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    /*public static <T> CommonResponse okMsg(String message ){
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(102);
        response.setMessage(message);
        response.setData(data);
        return response;
    }*/

    public static <T> CommonResponse okMsg(int code,String message , T data){
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(code);
        response.setMessage(message);
        response.setData(data);
        return response;
    }
}
